import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { getAccessToken } from '@/api/ysApi'

export const useYsStore = defineStore('ys', () => {
  const accessToken = ref('')
  const tokenMap:any = {}

  const getToken = async (appKey:string, appSecret:string) => {
    if (tokenMap[appKey]) {
        return tokenMap[appKey]
    }
    let res = await getAccessToken({
        appKey: appKey,
        appSecret: appSecret
    })
    accessToken.value = res.data.accessToken
    tokenMap[appKey] = res.data.accessToken
    return res.data.accessToken
}

  return { accessToken,tokenMap, getToken }
})
